Integrating Rasters and Vector Data

HES 505 Fall 2023: Session 16

Matt Williamson

Today’s Plan

Objectives

  • Use dplyr with predicates and measures to subset and manipulate data

  • Use extract to access raster data

  • Use zonal to summarize access data

  • Join data into a single analyzable dataframe

Motivating Question

How do Collaborative Forest Landscape Restoration projects compare to other National Forest lands with respect to social and wildfire risks?

Setting up some pseudocode

Subsetting to the relevant data

  • Where are the National Forests?
tmp <- tempfile()
fs.url <- "https://data.fs.usda.gov/geodata/edw/edw_resources/shp/S_USA.AdministrativeForest.zip"
download.file(fs.url, tmp)
temp2 <- tempfile()
unzip(zipfile = tmp, exdir = temp2)
fs.bdry <- read_sf(temp2)
all(st_is_valid(fs.bdry))
[1] FALSE
fs.bdry.valid <- st_make_valid(fs.bdry)

Subsetting to the relevant data

  • Where are the National Forests?

  • Using []

pnw <- counties(c("ID", "WA", "OR"), progress_bar=FALSE) %>% 
  st_transform(, crs=st_crs(fs.bdry))
fs.pnw <- fs.bdry.valid[pnw,]

tm_shape(pnw) +
  tm_polygons(border.col = "black") +
  tm_shape(fs.pnw) +
  tm_polygons(col="darkgreen")

Getting the CEJST tracts

  • Load from server

Choose the CEJST tracts

Select the appropriate variables

Extract raster data